package com.team11.server.controller.teacher;


import com.team11.server.pojo.dto.CheckWork;
import com.team11.server.pojo.dto.RespBean;
import com.team11.server.pojo.dto.StudentAnswer;
import com.team11.server.pojo.dto.WorkTask;
import com.team11.server.service.IHomeworkService;
import com.team11.server.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author pjc
 * @since 2021-06-17
 */
@CrossOrigin
@RestController
@RequestMapping("/teacher")
@Api(tags = "教师接口")
public class TeacherHomeworkController {
    @Autowired
    private IHomeworkService homeworkService;

    @ApiOperation("作业管理-->作业审核：获取学生答题详情")
    @GetMapping("/getStudentAnswer")
    public StudentAnswer getStudentAnswer(@RequestParam("homeworkId") Integer homeworkId) {
        return homeworkService.getStudentAnswer(homeworkId);
    }

    @ApiOperation("作业管理-->作业审核：获取老师检查作业详情")
    @PostMapping("/getCheckWork")
    public CheckWork getCheckWork(@RequestParam("homeworkId") Integer homeworkId) {
        return homeworkService.getCheckWork(homeworkId);
    }

    @ApiOperation("作业管理-->作业审核：老师检查作业")
    @PostMapping("/CheckWork")
    public RespBean CheckWork(@Validated CheckWork checkWork,
                              BindingResult result,
                              MultipartFile[] files, HttpServletRequest request) throws Exception{
        if (result.hasErrors()) {
            Map err= Result.notNull(result);
            return RespBean.error("", err);
        }
        return homeworkService.CheckWork(checkWork, files, request);
    }

}
